<?php

class DBMEntityTranslator implements DBMTranslator {
	/**
	 * Translate the entity to the SQL Server notation
	 *
	 * @param DBMEntity $entity
	 * @param DBMCommand $command
	 */
	public static function translateToSQLServer($entity, $command = null){
		if($command != null && ( 
			$command->getOperation() == DBMOperations::INSERT ||
			$command->getOperation() == DBMOperations::UPDATE ||
			$command->getOperation() == DBMOperations::DELETE 
		)){
			if($entity->getSchema() == null){
				return sprintf("[%s]", $entity->getTable());
			} else {
				return sprintf("[%s].[%s]", $entity->getSchema(), $entity->getTable());
			}	
		} else {
			if($entity->getSchema() == null){
				return sprintf("[%s] %s", $entity->getTable(), $entity->getAlias());
			} else {
				return sprintf("[%s].[%s] %s", $entity->getSchema(), $entity->getTable(), $entity->getAlias());
			}
		}
	}
	
	/**
	 * Translate the entity to the MySQL notation
	 *
	 * @param DBMEntity $entity
	 * @param DBMCommand $command
	 */
	public static function translateToMySQL($entity, $command = null){
		if($command != null && ( 
			$command->getOperation() == DBMOperations::INSERT ||
			$command->getOperation() == DBMOperations::DELETE 
		)){
			return sprintf("%s", $entity->getTable());
		} else {
			return sprintf("%s %s", $entity->getTable(), $entity->getAlias());
		}
	}
	
	/**
	 * Translate the entity to the PostreSQL notation
	 *
	 * @param DBMEntity $entity
	 * @param DBMCommand $command
	 */
	public static function translateToPostgreSQL($entity, $command = null){
		if($command != null && ( 
			$command->getOperation() == DBMOperations::INSERT ||
			$command->getOperation() == DBMOperations::UPDATE ||
			$command->getOperation() == DBMOperations::DELETE 
		)){
			if($entity->getSchema() == null){
				return sprintf("%s", $entity->getTable());
			} else {
				return sprintf("%s.%s", $entity->getSchema(), $entity->getTable());
			}	
		} else {
			if($entity->getSchema() == null){
				return sprintf("%s %s", $entity->getTable(), $entity->getAlias());
			} else {
				return sprintf("%s.%s %s", $entity->getSchema(), $entity->getTable(), $entity->getAlias());
			}
		}
	}
}

?>
